package com.walsai.pcsys.core.dao.hibernate;

import java.util.List;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;

import com.walsai.pcsys.core.model.User;
import com.walsai.pcsys.core.dao.SolutionDao;
import com.walsai.pcsys.core.model.Solution;
import com.walsai.pcsys.core.model.SolutionPK;

public class SolutionDaoHibernate extends
		GenericDaoHibernate<Solution, SolutionPK> implements SolutionDao {

	public SolutionDaoHibernate() {
		super(Solution.class);
		// TODO Auto-generated constructor stub
	}

	public List<Solution> getSolutions(User u) {
		Session s = this.getSession();
		List<Solution> list = null;
		try {
			list = s.createCriteria(Solution.class).add(Restrictions.eq("solutionPK.user", u)).list();
		} catch (HibernateException e) {
			e.printStackTrace();
		} finally {
			if (s != null) {
				try {
					s.close();
				} catch (HibernateException e) {
					e.printStackTrace();
				}
			}
		}

		return list;

	}
}
